﻿<phone:PhoneApplicationPage x:Class="SAFPodcast.WP8.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:ctrl="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:ignore="http://www.ignore.com"
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
    xmlns:converters="clr-namespace:SAFPodcast.WP8.Fwk.Converter;assembly=SAFPodcast.WP8.Fwk"
    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" 
    xmlns:MvvmLight="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.WP8"
    mc:Ignorable="d ignore"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait"
    Orientation="Portrait"
    d:DesignWidth="480"
    d:DesignHeight="696"
    shell:SystemTray.IsVisible="True"
    DataContext="{Binding Main, Source={StaticResource Locator}}">

  <phone:PhoneApplicationPage.Resources>
    <converters:NotConverter x:Key="NotConverter" />
    <converters:VisibilityConverter x:Key="VisibilityConverter" />
    <converters:VisibilityNotConverter x:Key="VisibilityNotConverter" />
  </phone:PhoneApplicationPage.Resources>

  <Grid x:Name="LayoutRoot" Background="Transparent">
    <ctrl:Pivot SelectionChanged="Pivot_SelectionChanged" Title="{Binding Path=Global.Application_Title, Source={StaticResource LocalizedStrings}}">
      <ctrl:PivotItem Header="{Binding Path=Global.Download_Title, Source={StaticResource LocalizedStrings}}">
        <Grid>
          <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
          </Grid.RowDefinitions>
          <TextBox TextChanged="TextBox_TextChanged"
            Text="{Binding UrlPodcastAsString, Mode=TwoWay, UpdateSourceTrigger=Explicit}"
            IsEnabled="{Binding CanDownloadPodcast}" />
          <ProgressBar Grid.Row="1"
            Value="{Binding CompletionPodcast}" Maximum="100"
            Visibility="{Binding IsDownloadingPodcast, Converter={StaticResource VisibilityConverter}}" />
          <Button Grid.Row="2" Command="{Binding DownloadPodcast}"
            IsEnabled="{Binding CanDownloadPodcast}"
            Content="{Binding Path=Global.Download_Button_Start, Source={StaticResource LocalizedStrings}}" />
          <toolkit:ToggleSwitch Grid.Row="3"
            Header="run under lock screen"
            IsChecked="{Binding RunningUnderLockScreenEnabled, Mode=TwoWay}" />
        </Grid>
      </ctrl:PivotItem>
      <ctrl:PivotItem x:Name="piFeeds" Header="Feeds">
        <Grid>
          <Grid.RowDefinitions>
            <RowDefinition Height="*" />
          </Grid.RowDefinitions>
          <ListBox x:Name="lbFeeds" Margin="0,0,-12,0" ItemsSource="{Binding Feeds}">
            <toolkit:GestureService.GestureListener>
              <toolkit:GestureListener />
            </toolkit:GestureService.GestureListener>
            <ListBox.ItemTemplate>
              <DataTemplate>
                <StackPanel Margin="0,0,0,17" Width="432" Height="78" toolkit:TiltEffect.IsTiltEnabled="True">
                  <toolkit:ContextMenuService.ContextMenu>
                    <toolkit:ContextMenu IsZoomEnabled="True">
                      <toolkit:MenuItem Header="Renommer"
                          Command="{Binding ElementName=lbFeeds, Path=DataContext.EditFeed}"
                          CommandParameter="{Binding}" />
                      <toolkit:MenuItem Header="Supprimer"
                          Command="{Binding ElementName=lbFeeds, Path=DataContext.DeleteFeed}"
                          CommandParameter="{Binding}" />
                    </toolkit:ContextMenu>
                  </toolkit:ContextMenuService.ContextMenu>
                  <TextBlock Text="{Binding Name}"
                      TextWrapping="NoWrap"
                      Style="{StaticResource PhoneTextExtraLargeStyle}">
                    <i:Interaction.Triggers>
                      <i:EventTrigger EventName="Tap">
                        <MvvmLight:EventToCommand
                          Command="{Binding ElementName=lbFeeds, Path=DataContext.ViewFeed}" 
                          CommandParameter="{Binding SelectedItem, ElementName=lbFeeds}"/>
                      </i:EventTrigger>
                    </i:Interaction.Triggers>
                  </TextBlock>
                </StackPanel>
              </DataTemplate>
            </ListBox.ItemTemplate>
          </ListBox>
          <Button x:Name="btnAdd" Command="{Binding AddFeed}" Visibility="Collapsed"></Button>
          <Button x:Name="btnSend" Command="{Binding SendErrors}" Visibility="Collapsed"></Button>
        </Grid>
      </ctrl:PivotItem>
    </ctrl:Pivot>
  </Grid>

  <toolkit:TransitionService.NavigationInTransition>
    <toolkit:NavigationInTransition>
      <toolkit:NavigationInTransition.Backward>
        <toolkit:TurnstileTransition Mode="BackwardIn"/>
      </toolkit:NavigationInTransition.Backward>
      <toolkit:NavigationInTransition.Forward>
        <toolkit:TurnstileTransition Mode="ForwardIn"/>
      </toolkit:NavigationInTransition.Forward>
    </toolkit:NavigationInTransition>
  </toolkit:TransitionService.NavigationInTransition>
  <toolkit:TransitionService.NavigationOutTransition>
    <toolkit:NavigationOutTransition>
      <toolkit:NavigationOutTransition.Backward>
        <toolkit:TurnstileTransition Mode="BackwardOut"/>
      </toolkit:NavigationOutTransition.Backward>
      <toolkit:NavigationOutTransition.Forward>
        <toolkit:TurnstileTransition Mode="ForwardOut"/>
      </toolkit:NavigationOutTransition.Forward>
    </toolkit:NavigationOutTransition>
  </toolkit:TransitionService.NavigationOutTransition>

  <phone:PhoneApplicationPage.ApplicationBar>
    <shell:ApplicationBar Mode="Minimized">
      <shell:ApplicationBarIconButton IconUri="/Toolkit.Content/appbar.add.rest.png" Text="Ajouter Flux" Click="abiAdd_Click" />
      <shell:ApplicationBar.MenuItems>
        <shell:ApplicationBarMenuItem Text="Envoyer les erreurs par mail" Click="bimSend_Click" />
      </shell:ApplicationBar.MenuItems>
    </shell:ApplicationBar>
  </phone:PhoneApplicationPage.ApplicationBar>
</phone:PhoneApplicationPage>
